from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-01-01 14:03:29.008809
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 01, Jan, 2022
Time: 14:03:34
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.6546
Nobs: 523.000 HQIC: -48.1006
Log likelihood: 6064.42 FPE: 9.67245e-22
AIC: -48.3876 Det(Omega_mle): 8.15655e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.368218 0.076808 4.794 0.000
L1.Burgenland 0.100221 0.043363 2.311 0.021
L1.Kärnten -0.113765 0.022350 -5.090 0.000
L1.Niederösterreich 0.180412 0.089945 2.006 0.045
L1.Oberösterreich 0.103270 0.089716 1.151 0.250
L1.Salzburg 0.279168 0.046586 5.993 0.000
L1.Steiermark 0.026380 0.060172 0.438 0.661
L1.Tirol 0.109577 0.048622 2.254 0.024
L1.Vorarlberg -0.077944 0.042855 -1.819 0.069
L1.Wien 0.030413 0.080915 0.376 0.707
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.028823 0.168981 0.171 0.865
L1.Burgenland -0.046546 0.095400 -0.488 0.626
L1.Kärnten 0.036883 0.049171 0.750 0.453
L1.Niederösterreich -0.211802 0.197884 -1.070 0.284
L1.Oberösterreich 0.453426 0.197379 2.297 0.022
L1.Salzburg 0.309222 0.102491 3.017 0.003
L1.Steiermark 0.112392 0.132382 0.849 0.396
L1.Tirol 0.313472 0.106971 2.930 0.003
L1.Vorarlberg 0.014890 0.094282 0.158 0.875
L1.Wien -0.001027 0.178018 -0.006 0.995
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.215660 0.039138 5.510 0.000
L1.Burgenland 0.093227 0.022096 4.219 0.000
L1.Kärnten -0.005576 0.011388 -0.490 0.624
L1.Niederösterreich 0.226355 0.045832 4.939 0.000
L1.Oberösterreich 0.159575 0.045715 3.491 0.000
L1.Salzburg 0.038514 0.023738 1.622 0.105
L1.Steiermark 0.029816 0.030661 0.972 0.331
L1.Tirol 0.078664 0.024776 3.175 0.001
L1.Vorarlberg 0.055150 0.021837 2.526 0.012
L1.Wien 0.109805 0.041231 2.663 0.008
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.150907 0.039141 3.856 0.000
L1.Burgenland 0.040609 0.022097 1.838 0.066
L1.Kärnten -0.013081 0.011389 -1.149 0.251
L1.Niederösterreich 0.160371 0.045835 3.499 0.000
L1.Oberösterreich 0.333749 0.045719 7.300 0.000
L1.Salzburg 0.101821 0.023740 4.289 0.000
L1.Steiermark 0.111802 0.030663 3.646 0.000
L1.Tirol 0.089983 0.024777 3.632 0.000
L1.Vorarlberg 0.054135 0.021838 2.479 0.013
L1.Wien -0.031183 0.041234 -0.756 0.449
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.131885 0.073507 1.794 0.073
L1.Burgenland -0.038073 0.041499 -0.917 0.359
L1.Kärnten -0.039145 0.021389 -1.830 0.067
L1.Niederösterreich 0.135090 0.086080 1.569 0.117
L1.Oberösterreich 0.171776 0.085860 2.001 0.045
L1.Salzburg 0.266182 0.044584 5.970 0.000
L1.Steiermark 0.074652 0.057586 1.296 0.195
L1.Tirol 0.138013 0.046532 2.966 0.003
L1.Vorarlberg 0.098230 0.041013 2.395 0.017
L1.Wien 0.064790 0.077438 0.837 0.403
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.084833 0.057857 1.466 0.143
L1.Burgenland 0.018124 0.032664 0.555 0.579
L1.Kärnten 0.051818 0.016835 3.078 0.002
L1.Niederösterreich 0.181559 0.067753 2.680 0.007
L1.Oberösterreich 0.325489 0.067580 4.816 0.000
L1.Salzburg 0.048757 0.035092 1.389 0.165
L1.Steiermark -0.001369 0.045326 -0.030 0.976
L1.Tirol 0.126059 0.036626 3.442 0.001
L1.Vorarlberg 0.061654 0.032281 1.910 0.056
L1.Wien 0.104271 0.060951 1.711 0.087
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170511 0.070205 2.429 0.015
L1.Burgenland 0.012008 0.039635 0.303 0.762
L1.Kärnten -0.061895 0.020429 -3.030 0.002
L1.Niederösterreich -0.113793 0.082214 -1.384 0.166
L1.Oberösterreich 0.220538 0.082004 2.689 0.007
L1.Salzburg 0.041277 0.042581 0.969 0.332
L1.Steiermark 0.261844 0.055000 4.761 0.000
L1.Tirol 0.489668 0.044443 11.018 0.000
L1.Vorarlberg 0.067687 0.039171 1.728 0.084
L1.Wien -0.084309 0.073960 -1.140 0.254
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.146740 0.077707 1.888 0.059
L1.Burgenland -0.009494 0.043870 -0.216 0.829
L1.Kärnten 0.064132 0.022611 2.836 0.005
L1.Niederösterreich 0.171828 0.090998 1.888 0.059
L1.Oberösterreich -0.073646 0.090766 -0.811 0.417
L1.Salzburg 0.218391 0.047131 4.634 0.000
L1.Steiermark 0.142485 0.060877 2.341 0.019
L1.Tirol 0.051877 0.049191 1.055 0.292
L1.Vorarlberg 0.144624 0.043356 3.336 0.001
L1.Wien 0.145842 0.081863 1.782 0.075
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.454506 0.044119 10.302 0.000
L1.Burgenland -0.002031 0.024908 -0.082 0.935
L1.Kärnten -0.015950 0.012838 -1.242 0.214
L1.Niederösterreich 0.184624 0.051666 3.573 0.000
L1.Oberösterreich 0.230453 0.051534 4.472 0.000
L1.Salzburg 0.027417 0.026760 1.025 0.306
L1.Steiermark -0.011600 0.034564 -0.336 0.737
L1.Tirol 0.078822 0.027929 2.822 0.005
L1.Vorarlberg 0.050784 0.024616 2.063 0.039
L1.Wien 0.005695 0.046479 0.123 0.902
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.029911 0.091350 0.158658 0.140805 0.072640 0.080587 0.014041 0.209180
Kärnten 0.029911 1.000000 -0.030355 0.132482 0.048759 0.077107 0.452765 -0.076392 0.095692
Niederösterreich 0.091350 -0.030355 1.000000 0.296619 0.110145 0.256113 0.053781 0.146501 0.257995
Oberösterreich 0.158658 0.132482 0.296619 1.000000 0.204225 0.285781 0.160569 0.129028 0.207064
Salzburg 0.140805 0.048759 0.110145 0.204225 1.000000 0.119934 0.064118 0.105600 0.088190
Steiermark 0.072640 0.077107 0.256113 0.285781 0.119934 1.000000 0.130484 0.092551 0.009311
Tirol 0.080587 0.452765 0.053781 0.160569 0.064118 0.130484 1.000000 0.060288 0.134498
Vorarlberg 0.014041 -0.076392 0.146501 0.129028 0.105600 0.092551 0.060288 1.000000 -0.018574
Wien 0.209180 0.095692 0.257995 0.207064 0.088190 0.009311 0.134498 -0.018574 1.000000